<?php

namespace app\admin\controller;

use app\admin\service\ExpressService;
use support\spark\model\system\SetExpress;
use support\Request;
use support\View;

class ExpressController extends Curd
{
    public function index()
    {
        if (request()->isAjax()) {
            $param = request()->all();
            $expressService = new ExpressService();
            $res = $expressService->getList($param);
            return sparkSuccess($res);
        }
        return view('express/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $expressService = new ExpressService();
            $res = $expressService->addExpress($param);
            return sparkSuccess($res);
        }
        return view('express/add');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $expressService = new ExpressService();
            $res = $expressService->editExpress($param);
            return sparkSuccess($res);
        }

        $id = request()->get('id');
        $setExpressModel = new SetExpress();
        View::assign([
            'info' => $setExpressModel->getInfoByWhere([
                'id' => $id
            ])
        ]);

        return view('express/edit');
    }
    /**
     * 删除
     */
    public function del()
    {
        $id = request()->get('id');

        $setExpressModel = new SetExpress();
        $setExpressModel->delById($id);
        return sparkSuccess(dataReturn(0,'删除成功'));
    }

}